﻿using System;
using System.Collections.Generic;
using System.Text;
using WAD.WEB.AppCode;
using WAD.Model;
using WAD.DAL;

namespace WAD.WEB.Admin.Ajax
{
    /// <summary>
    /// FC_Article 的摘要说明
    /// </summary>
    public class FC_Article : AdminAjax
    {
        public override void AjaxMethodDispatch(String identity)
        {
            switch (identity)
            {
                case "getlist": this.GetList(); break;
                case "getlist_no": this.GetList_No(); break;
            }
        }
        /// <summary>
        /// 用户列表
        /// </summary>
        [QD.Web.Ajax.AjaxMethod]
        public void GetList()
        {
            int pageIndex = Parse.Int("page_index", 1);//当前页
            int state = Parse.Int("state", -1);
            int user_id = Parse.Int("userid", -1);
            int is_pass = Parse.Int("is_pass", -1);
            StringBuilder sb = new StringBuilder();
            sb.Append("1=1");
            if (state > -1)
                sb.AppendFormat(" and state={0}", state);

            if (user_id > 0)
                sb.AppendFormat(" and user_id={0}", user_id);

            if (!string.IsNullOrEmpty(Parse.String("title", "")))
                sb.AppendFormat("and title like '%{0}%'", Parse.String("title", ""));

            ////is_pass   (null 未审核, 0已拒绝, 1已通过,2 审核中)
            //if (is_pass > -1)
            //    sb.AppendFormat(" and id in (select article_id from fc_shared where is_pass={0})", is_pass);
            //else
            //    sb.Append(" and id in (select article_id from fc_shared where isnull(is_pass,0)=0)");

            PageData pg = DAOFCArticle.GetListPage("*", "id desc", pageIndex, 20, sb.ToString(), "fc_article");
            if (pg.itemCount == 0)
                DataEmpty();
            else
                Success(pg);
        }

        /// <summary>
        /// 拒绝过的红包文章
        /// </summary>
        [QD.Web.Ajax.AjaxMethod]
        public void GetList_No()
        {
            int pageIndex = Parse.Int("page_index", 1);//当前页
            int state = Parse.Int("state", -1);
            int user_id = Parse.Int("userid", -1);
            StringBuilder sb = new StringBuilder();
            sb.Append("1=1");
            if (state > -1)
                sb.AppendFormat(" and state={0}", state);

            if (user_id > 0)
                sb.AppendFormat(" and user_id={0}", user_id);

            if (!string.IsNullOrEmpty(Parse.String("title", "")))
                sb.AppendFormat("and title like '%{0}%'", Parse.String("title", ""));

            sb.Append(" and id in (select article_id from fc_shared where is_pass>1)");

            PageData pg = DAOFCArticle.GetListPage("*", "id desc", pageIndex, 20, sb.ToString(), "fc_article");
            if (pg.itemCount == 0)
                DataEmpty();
            else
                Success(pg);
        }
    }
}